package com.poetize.plus.properties;

import com.poetize.plus.annotation.Secret;
import com.poetize.plus.enums.AlgorithmEnum;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.time.temporal.ChronoUnit;
import java.util.Set;

/**
 * @author zuosy
 * @created 2024/3/28 15:26
 */
@Getter
@Component
@Validated
@ConfigurationProperties(prefix = "security")
public class SecurityProperties {

    /**
     * 白名单
     */
    private Set<String> whiteUrl;

    private final Jwt jwt = new Jwt();

    public void setWhiteUrl(Set<String> whiteUrl) {
        this.whiteUrl = whiteUrl;
    }

    @Data
    public static class Jwt{

        /**
         * 密钥
         */
        @Secret
        private String secret;

        /**
         * 算法类型
         */
        @NotNull(message = "算法类型不能为空")
        private AlgorithmEnum algorithm;

        /**
         * 日期单位
         */
        @NotNull(message = "日期单位不能为空")
        private ChronoUnit chronoUnit;

        /**
         * 过期时间
         */
        @NotNull(message = "过期时间不能为空")
        @Min(value = 1,message = "过期时间不能低于{value}分钟")
        private Integer expire;

        /**
         * 签名
         */
        @NotBlank(message = "签名不能为空")
        private String issuer;

        /**
         * 主题
         */
        @NotBlank(message = "主题")
        private String subject;

        /**
         * 可刷新时长
         */
        @NotNull(message = "可刷新时长不能为空")
        @Min(value = 1440,message = "可刷新时长不能低于{value}min")
        private Integer refreshExpiration;
    }
}
